package com.xxkj.drugtraceability.ui.drugoutscan

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.xxkj.drugtraceability.R
import com.xxkj.drugtraceability.bean.DrugTrace
import com.xxkj.drugtraceability.databinding.LayoutDrugScanBinding
import com.xxkj.drugtraceability.ext.clickN

/**
 * author: zhoujingjin
 * created on: 2024/9/11 10:27
 * description:
 */
class DrugOutScanAdapter(private val actionDelete:(index:Int)->Unit):
    BaseQuickAdapter<DrugTrace, BaseDataBindingHolder<LayoutDrugScanBinding>>(R.layout.layout_drug_scan) {
    var hasData = false
    fun setState( hasData:Boolean){
        this.hasData = hasData
    }
    override fun convert(holder: BaseDataBindingHolder<LayoutDrugScanBinding>, item: DrugTrace) {
        holder.dataBinding?.apply {
            data = item.drugTracCodg
            if (hasData){
                ivDelete.visibility = View.INVISIBLE
            }else{
                ivDelete.clickN {
                    actionDelete.invoke(getItemPosition(item))
                }
                ivDelete.visibility = View.VISIBLE
            }
        }
    }
}